<div class="contents">
    <div class="top_all_box">
        <div class="top_all_goods"><{if $search_keywords}><{$search_keywords}> <{else}> <{$cat_name}><{/if}></div>
        <div class="top_all_goods_solid"></div>
        <a href="./">
          <{img class="top_all_img" src="images/bottom_1.png" app='wap'}>
        </a>
        <div class="top_all_choice"><span class="hook_show <{if $is_store}>hook_show_selected<{/if}>"></span>仅显示有货</div>
    </div>
    <div class="content-padded grid-demo top_screen_box">
        <div class="row no-gutter trigger-list" style="display: flex;">
          <div class="col-25 top_screen top_screen_solid default ">综合</div>
          <div class="col-25 top_screen top_screen_solid store-seq">库存<span class="screen_arrow"></span></div>
          <div class="col-25 top_screen top_screen_solid price-seq">价格<span class="screen_arrow"></span></div>
          <div class="col-25 top_screen filter-handle">筛选<span class="screen_arrow_a"></span>
            <div id="filter_container" style="display:none;">
                <{include file='wap/gallery/screen.html'}>
            </div>
          </div>
        </div>
    </div>
</div>
<div class="row nomargin nopadding panel-list" style="background: #fff;height: 79%;overflow: auto;padding-bottom: 0px;margin-left: 0px;">
    <{include file='wap/gallery/type/list.html'}>
</div>
<script type="text/javascript">
(function(){
// $(".screen_store").click(
//     function(){
//       // $('.top_screen_solid').removeClass('top_screen_now');
//       $(this).siblings('.top_screen_solid').removeClass('top_screen_now');
//       $(this).addClass("top_screen_now")
//       $(this).find(".screen_arrow").addClass("screen_store_up")
//       $(this).find(".screen_arrow").toggleClass("screen_store_bottom");
//     }
//   )
$('.nav_top_bg').eq(0).hide();
$('.content').css({'top':'0','bottom':'-27px'});
$('.bar').css({'position':'fixed'});
  var container = document.body;
  var priceSeq = 'price desc';
  var storeSeq = 'jxc_store desc';
  var url = '<{link app=b2c ctl=wap_gallery act=ajax_get_goods}>';
  var page = '<{$page}>';
  var cat_id = '<{$screen.cat_id}>';
  var filter_dialog;

  $(".hook_show").click(
    function(){
        $(this).toggleClass("hook_show_selected");
        var is_store= 0;
        if ($(this).hasClass('hook_show_selected')) {
          is_store=1;
        }else{
          is_store=0;
        }
        filterGoods($('.trigger-list .top_screen_now'),null,is_store);
    }
  )

  function filterGoods(t,e,is_store){
    var vcat = '<{$filter.virtual_cat_id}>';
    var orderby = 'orderBy=',
        p = 'page=',
        sear = '',
        search = location.search;
    if(e&&$('.trigger-list .top_screen_now').hasClass('price-seq')) orderby += priceSeq;
    else if(e&&$('.trigger-list .top_screen_now').hasClass('store-seq')) orderby += storeSeq;
    else if(t.hasClass('default')){
        orderby += 'bn asc';
    }
    else if(t.hasClass('price-seq')){
        orderby += priceSeq;
    }
    else if(t.hasClass('store-seq')){
        orderby += storeSeq;
    }
    if(e&&e.num){
        p += e.num;
        page = e.num;
    }
    if(search) sear = search.substr(1);

    var params = ['showtype=list', p, sear,encodeURI(orderby),$('#J_filter form').serialize()];
    if (is_store) {
      params.push('is_store=1');
    }
    if (vcat) {
      params.push('virtual_cat_id='+vcat);
    }
    params = params.join('&');
    $.post(url, params, function(re){
        $('.panel-list').html(re);
        var reg = new RegExp(location.hash || location.href, 'i');
        window.history.pushState({url: location.href, html: container.innerHTML}, null, location.href.replace(reg, '#' + params));
    });
  }
  $('.no-gutter .top_screen_solid').on('touchend',function(e){e.preventDefault();}).on('tap',function(){
    $(this).siblings('.top_screen_solid').removeClass('top_screen_now');
    $(this).siblings('.top_screen_solid').find('span').removeClass('screen_store_bottom');
    $(this).siblings('.top_screen_solid').find('span').removeClass('screen_store_up');
    $(this).addClass("top_screen_now")
    page = 1;
    var is_store=0;
    if ($('.hook_show').hasClass('hook_show_selected')) {
      is_store=1;
    }else{
      is_store=0;
    }
    if( $(this).hasClass('store-seq') ){
        // storeSeq = storeSeq == 'jxc_store desc' ? 'jxc_store asc' : 'jxc_store desc';
        if(storeSeq == 'jxc_store desc'){
            storeSeq = 'jxc_store asc';
            $(this).find('span')[0].removeClass("screen_store_bottom");
            $(this).find('span')[0].addClass("screen_store_up");
        }else{
            storeSeq = 'jxc_store desc';
            $(this).find('span')[0].addClass("screen_store_bottom");
        }
    }else if ($(this).hasClass('price-seq')) {
        if(priceSeq == 'price desc'){
            priceSeq = 'price asc';
            $(this).find('span')[0].removeClass("screen_store_bottom");
            $(this).find('span')[0].addClass("screen_store_up");
        }else{
            priceSeq = 'price desc';
            $(this).find('span')[0].addClass("screen_store_bottom");
        }
    }
    filterGoods($(this),null,is_store);
  });

  $('.panel-list').on('click',function(e){
    var t = $(e.target);
    var is_store=0;
    if ($('.hook_show').hasClass('hook_show_selected')) {
      is_store=1;
    }else{
      is_store=0;
    }
    if(t.hasClass('flip')){
      t.num = parseInt(t.attr('page'));
      if(t.hasClass('next'))t.num = parseInt(page)+1;
      if(t.hasClass('prev'))t.num = parseInt(page)-1;
      filterGoods($('.trigger-list .top_screen_now'),t,is_store);
      return false;
    }
  }).on('change','select',function(){
    var t = $(this.options[this.selectedIndex]);
    var is_store=0;
    if ($('.hook_show').hasClass('hook_show_selected')) {
      is_store=1;
    }else{
      is_store=0;
    }
    if(t.hasClass('flip')){
      t.num = parseInt(t.attr('page'));
      filterGoods($('.trigger-list .top_screen_now'),t,is_store);
    }
  });
  //筛选
  $('.filter-handle').on('tap',function(){
    page = 1;
    filter_dialog = new Dialog('#filter_container',{'type':'confirm'});
  });
  $('#J_filter').on('touchend',function(e){e.preventDefault();}).on('tap',function(event){
    var _this = this,
    t = $(event.target),
    tag = t[0].tagName.toLowerCase(),
    table = t.parents('table');
    switch(tag){
      case 'dt':
        if( t.hasClass('handle') ){
          t.removeClass('handle').next().addClass('hide');
        }else{
          t.addClass('handle').next().removeClass('hide');
          t.siblings('.handle').removeClass('handle').next().addClass('hide');
        }
        break;
      case 'td':
        if(t.hasClass('empty'))return;
        table.find('td').removeClass('handle');
        t.addClass('handle');
        table.parent().prev().find('span').html(t.html());
        var fid = t.attr('data-fid');
        if(fid&&fid.length){
          fid = fid.split('-');
          table.prev().attr({name:fid[0]+'[]',value:fid[1]});
          table.parent().prev().find('span').addClass('act');
        }else{
          var hide = table.prev();
          if(/^cat_id/.test(hide.attr('name'))) {
              hide.val(cat_id);
          }
          else {
              hide.val('');
          }
          table.parent().prev().find('span').removeClass('act');
        }
        break;
      case 'span':
        if(t.hasClass('reset')){
          $.each($(this).find('table'),function(){
            $(this).find('td').eq(0).trigger('tap');
          });
        }
        break;
      case 'input':
        filterGoods( $('.trigger-list .top_screen_now'),t );
        filter_dialog.close();
        break;
    }
  });
  })();
</script>